package net.example.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;

import net.example.model.GGUser;
import net.example.ggtalk.R;

public class HeadImgHelper {

    //设置用户的头像
    public static void setUserHeadImg(ImageView imageView, GGUser GGUser) {
        try {
            int head = R.drawable.default_qq_avatar;
            if(GGUser ==null)
            {
                imageView.setImageResource(head);
                return;
            }
            int index = GGUser.getHeadImageIndex();
            if (index == -1) {
                byte[] datas = GGUser.getHeadImageData();
                Bitmap bitmap = BitmapFactory.decodeByteArray(datas, 0, datas.length);
                imageView.setImageBitmap(bitmap);
                return;
            }
            switch (index) {
                case 0: {
                    head = R.drawable.h0;
                    break;
                }
                case 1: {
                    head = R.drawable.h1;
                    break;
                }
                case 2: {
                    head = R.drawable.h2;
                    break;
                }
                case 3: {
                    head = R.drawable.h3;
                    break;
                }
                case 4: {
                    head = R.drawable.h4;
                    break;
                }
                case 5: {
                    head = R.drawable.h5;
                    break;
                }
                case 6: {
                    head = R.drawable.h6;
                    break;
                }
                case 7: {
                    head = R.drawable.h7;
                    break;
                }
                case 8: {
                    head = R.drawable.h8;
                    break;
                }
                case 9: {
                    head = R.drawable.h9;
                    break;
                }
            }
            imageView.setImageResource(head);
        }catch (Exception ee)
        {
            imageView.setImageResource(R.drawable.h0);
        }

    }
}
